package co.edu.unal.satacredito.rest.activities.general;

import co.edu.unal.satacredito.rest.domain.general.GenericTransaction;
import co.edu.unal.satacredito.rest.exceptions.visa.CannotValidateTransactionException;
import co.edu.unal.satacredito.rest.repositories.general.ValidateGenericTransactionRemote;
import co.edu.unal.satacredito.rest.representations.RestUri;
import co.edu.unal.satacredito.rest.representations.general.GenericTransactionRepresentation;
import co.edu.unal.satacredito.rest.util.Constants;
import co.edu.unal.satacredito.rest.util.ServiceLocator;

public class ValidateGenericTransactionActivity {
	
	/**
	 * 
	 * @param transaction
	 * @param uri
	 * @return
	 * @throws CannotValidateTransactionException
	 */
	public GenericTransactionRepresentation validate(
			GenericTransaction transaction, RestUri uri)
			throws CannotValidateTransactionException {

		GenericTransaction validatedTransaction = doValidation(transaction);

		return GenericTransactionRepresentation.createResponseRepresentation(validatedTransaction, uri);
	}

	/**
	 * 
	 * @param transaction
	 * @return
	 */
	private GenericTransaction doValidation(GenericTransaction transaction) {
		
		ValidateGenericTransactionRemote validateGenericTransactionRemote = (ValidateGenericTransactionRemote) ServiceLocator
				.getInstance().getResource(Constants.GENERIC_EJB);
		
		GenericTransaction validate = validateGenericTransactionRemote.validate(transaction);
		
		return validate;
		
	}
	
}
